package com.zmj.demo01;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;



public class Demo1 {

    public  static  void  main(String[]args) throws  Exception{

        //1,创建任务描述对象  JobDetail
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class).
                withIdentity("myJOb","myGroup").build();

        //2,创建触发器
        //withIntervalInSeconds(3).repeatForever()  每隔3秒执行一次
        SimpleTrigger simpleTrigger = TriggerBuilder.newTrigger().
                withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(3).repeatForever())
                .withIdentity("myTrigger","myGroup")
                .startNow().build();

        //3,创建调度器
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();

        //4,注册任务和触发器
        scheduler.scheduleJob(jobDetail,simpleTrigger);

        scheduler.start();



    }


}
